﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Wicresoft.SMS.Data;
using Wicresoft.SMS.Web;
using System.ComponentModel;
using System.Web.Mvc;
using System.ComponentModel.DataAnnotations;

namespace Wicresoft.SMS.Web.Areas.history.Models
{
    public class LinkImpIAuthorise : IAuthorise
    {
        AuthorisedMetadataModel _model;

        IUserRoleService _service = new FackUserRoleService();

        public AuthorisedMetadataModel model
        {
            get {
                return _model;
            }
            set {
                _model = value;
            }
        }

        public bool IsVisible
        {
            get {
                long value = 0;
                long[] values = _service.GetRolesValueForUser(_model.User);
                foreach (long v in values)
                    value |= v;
                if ((value & (long)_model.Flag) != (long)_model.Flag)
                    return false;
                return true;
            }
        }

        public bool IsEnable
        {
            get { throw new NotImplementedException(); }
        }
    }

    public class EditImpIAuthorise : IAuthorise
    {
        AuthorisedMetadataModel _model;
        public AuthorisedMetadataModel model
        {
            get {
                return _model;
            }
            set {
                _model = value;
            }
        }

        IUserRoleService _service = new FackUserRoleService();

        public bool IsVisible
        {
            get { return true; }
        }

        public bool IsEnable
        {
            get
            {
                long value = 0;
                long[] values = _service.GetRolesValueForUser(_model.User);
                foreach (long v in values)
                    value |= v;
                if ((value & (long)_model.Flag) != (long)_model.Flag)
                    return false;
                return true;
            }
        }
    }


    [AuthoriseImplement(typeof(LinkImpIAuthorise))]
    public class LeftMenu : BaseModelWithAuthorise
    {
        
        [AuthoriseFlag(AuthoriseFlag.page_sms_send)]
        [DisplayName("Send SMS(from Model Attribute)")]
        public string link_sendsms { get; set; }

        [AuthoriseFlag(AuthoriseFlag.page_sms_template)]
        public string link_smstemplate { get; set; }

        [AuthoriseFlag(AuthoriseFlag.page_addressbook)]
        [DisplayName("Address Book(from Model Attribute)")]
        public string link_addressbook { get; set; }

        [AuthoriseFlag(AuthoriseFlag.page_history)]
        public string link_history { get; set; }

        [AuthoriseFlag(AuthoriseFlag.page_groupmanage)]
        public string link_managegroup { get; set; }

        [AuthoriseFlag(AuthoriseFlag.page_usermanage)]
        public string link_manageuser { get; set; }

        [AuthoriseFlag(AuthoriseFlag.page_report_overview)]
        public string link_report_overview { get; set; }

        [AuthoriseFlag(AuthoriseFlag.page_report_history)]
        public string link_report_history { get; set; }

        [AuthoriseFlag(AuthoriseFlag.page_report_group)]
        public string link_report_group { get; set; }

        [AuthoriseFlag(AuthoriseFlag.page_report_user)]
        public string link_report_user{ get; set; }
    }

    [AuthoriseImplement(typeof(EditImpIAuthorise))]
    public class UserSetting : BaseModelWithAuthorise
    {

        [AuthoriseFlag(AuthoriseFlag.edit_home_setting_alias)]
        [AuthoriseControlType(Web.ControlType.text)]
        public string Alias { get; set; }

        [AuthoriseFlag(AuthoriseFlag.edit_home_setting_displayname)]
        [AuthoriseControlType(Web.ControlType.text)]
        public string DisplayName { get; set; }

        [AuthoriseFlag(AuthoriseFlag.edit_home_setting_pwd)]
        [AuthoriseControlType(Web.ControlType.password)]
        public string Password { get; set; }


        [AuthoriseFlag(AuthoriseFlag.edit_home_setting_alias)]
        [AuthoriseControlType(Web.ControlType.checkbox)]
        public bool IsAdmin { get; set; }

        [AuthoriseFlag(AuthoriseFlag.edit_home_setting_displayname)]
        [AuthoriseControlType(Web.ControlType.multi_select)]
        public IEnumerable<string> selector { get; set; }


        [AuthoriseFlag(AuthoriseFlag.edit_home_setting_pwd)]
        [AuthoriseControlType(Web.ControlType.submit)]
        [DisplayName("提交")]
        public string Submit { get; set; }
    }

}